activityName=$1
dayOffset=$2
work_path=$(dirname $(readlink -f $0))
outFolder="/var/www/html/shanbay"
logPath="$outFolder/log-check.txt"

if test -z "$activityName";
then
    activityName="早起团"
fi

if test -z "$dayOffset";
then
    dayOffset=0
fi

key=""
if [ $activityName = "早起团" ]
then
	key="zaoqi"
elif [ $activityName = "惜时社" ]
then
	key="xishi"
elif [ $activityName = "沁心运动" ]
then
	key="yundong"
else
	key="test"
fi

# check if token exist
tokenPath=$work_path/../tokens/$key

if [ ! -f "$tokenPath" ]; then
	echo "$tokenPath not exist, please save a valid token into it"
	# get auth_token
    # /usr/local/bin/python3.8 $updateTokenFile $activityName >> $logPath
else
	echo "Success to get file $tokenPath"
fi


htmlPath="$work_path/../output/$activityName$dayOffset.html"

if test -e $htmlPath; then
    rm $htmlPath;
fi

/root/.pyenv/shims/python $work_path/run_makePostsHtml.py $activityName $dayOffset >> $logPath
cp  $htmlPath $outFolder/
